﻿#region  Copyright (C) 2013 Unisys Corporation

// =============================================================================================
// All Rights Reserved. This work contains trade secrets and confidential material of UNISYS, 
// and its use or disclosure in whole or in part without explicit written permission of 
// UNISYS is prohibited. 
//  
// Product Name          :  Unisys e-Workflow and Imaging 8.2
// File Name             :  Service.cs
// Authored By           :  Unisys Corporation
// =============================================================================================
//	Modified by                         Date            Version
// =============================================================================================
//	ronald.aguilar@cr.unisys.com      Jun 06, 2013    Initial Version
// =============================================================================================

#endregion

#region Using Region
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Unisys.DuplicateCheck.Data.Logger;
#endregion

namespace Unisys.DuplicateCheck.Logic.Services
{

    public static class Service
    {
        public delegate void writeInWindows(string args);
        public static event writeInWindows eventWriteInWindows;
        public enum errorType { Error_Message, Log_Message, Information_Message, Proccess_Message };
        //mensaje a errores,mensaje a la bitacora, mensaje a trace, mensaje a procesos
        private static string _message = "";


        private static string message(int error, string description)
        {
            return DateTime.Now.ToString("yyyy'-'MM'-'dd HH':'mm':'ss':'fff") + " - " + Logger.ErrorMessage((int)error) + " - " + description + "\r\n";
        }

        public static string getMessage()
        {
            return _message;
        }

        public static void sendLog( string description, errorType error, Exception exc = null, string action = "", int cantidad = 0)
        {
            eventWriteInWindows( message((int)error, description));
            if (Logger.ifWrite((int)error))
            {
                #region File Write
                _message = message((int)error, description);
                if (Logger.ifFileWrite())
                {
                    try
                    {
                        Logger.fileWrite(_message);
                    }
                    catch { }
                }

                #endregion

               
            }

        }

    }
}
